<template>
  <div>
    
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
      <el-table-column prop="dynamicUser.userNick" label="时间" width="100">
        <template slot-scope="scope">
          {{timeFun(scope.row.comment.createtime)}}
        </template>
      </el-table-column>

      <el-table-column prop="comment.commentUser.userNick" label="ID" width="120"> </el-table-column>

      <el-table-column prop="address" label="内容">
        <template slot-scope="scope">
          <div>
            <div>{{scope.row.comment.commentContent}}</div>
            <div class="colorOne lineword">{{typeFun(scope.row)}}</div>
          </div>
        </template>
      </el-table-column>      
     
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <div>
            <el-button v-if="scope.row.comment.commentStatus ==0 && userRole.CM_1201001" class="addBtn" type="danger"  @click="deletData(scope.row.comment.commentId,4)"> 删除</el-button>
            <el-button v-if="scope.row.comment.commentStatus ==4 && userRole.CM_1201001" type="success" class="addBtn" @click="deletData(scope.row.comment.commentId,0)">恢复</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
   
    <el-dialog :visible.sync="imgstuts">
      <img width="100%" :src="titleImgurl" alt="">
    </el-dialog>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import getTime from '@/Http/getTime'
  import Http from '@/Http/Http'

  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        imgstuts:false,
        titleImgurl:'',
        tableData:[],
        total:0,
        currentPage4: 1,//分野
        page:1,
        pageSize:10
      }
    },
    created(){
      
      this.getlist()
    },
    props:['navStatus'],
    methods: {
      getlist(val) {
        const status = val || 0;
        const arr = [2,4,1,3];
        const obj = {
          "pageIndex":this.page,
          "pageSize":this.pageSize,
          "type":arr[this.navStatus],
          "status":status
        }
        Http.getCommentlist(obj)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
           this.dataArtice = '';
          this.articelStatus = false
        })
        .catch( error => {
          this.$message.error(`请求失败`)
          setTimeout(()=>{
            this.$router.push('/')
          },2000)
        })
      },
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        
      },
      timeFun(val) {
        return getTime(val)
      },
      typeFun(row){
        let i = '';
        let txt = ''
        switch (this.navStatus) {
          case 0:
             i = 'dynamci'
            if(!row[i]) return;
            if(!row[i].dynamicContent) return;
            txt = row[i].dynamicContent
            break
          case 1:
            i = 'xx';
           return
            break;
          case 2:
            i = 'article';
            txt = row[i].articleTitle
            break
          case 3:
            i = 'video';
            if(!row[i]) return ;
            txt = row[i][i].title
            break
        }
        return  txt
      },
      srcFun(obj){
        if(obj.indexOf('http://') > -1){
          return obj
        } else{
          obj = 'http://odqiuyfsp.bkt.clouddn.com/'+obj
        }
        return obj
      },
      //选择 推荐
      handleSelectionChange(val) {
        this.checkFun(val)
      },
      deletData(id,sta) {
        let txt ='';
        sta == 4 ? txt='删除' : txt='回复';
     
        Http.editCommentStatus({
          "status":sta,
          "commentId":id
        })
        .then( res => {
          if( res.data.code == 200 ){
            this.$message.success(`${txt}成功`)
            this.getlist()
          } else if(res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
           setTimeout(()=>{
              this.$router.push('/')
            },2000)
          }
        })
        .catch( res => {
          this.$message.error('服务器请求失败')
        })
      },
      checkFun(val) {  //选择方法
        this.$emit('checkFun',val)
      },
    
     
      goEdit(){
        this.$router.push('/Home/editor')
      },
      
      chageStatus(val) {
        let txt ='';
        val? txt ='开启' : txt = '关闭';
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      //导出
      exportXlxs() {
      },
       //搜索
      sheachFun(val){
        
      },
      //图片放大
      showImage(row){
        
        this.titleImgurl = row
        this.imgstuts = true
      }
      
    }
  }
</script>
<style>
.lineword{
  width: 96%;
  height:34px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}
</style>
